-
Notifications
You must be signed in to change notification settings - Fork 8.1k
drivers: eeprom: stm32: HAL return value handling #97279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
drivers: eeprom: stm32: HAL return value handling #97279
Conversation
drivers/eeprom/eeprom_stm32.c
Outdated
if (HAL_FLASHEx_DATAEEPROM_Unlock() != HAL_OK) { | ||
return -EIO; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: there should be consistency about whether driver uses
if (xxx() != HAL_OK) {
...fail
}
or
ret = xxx();
if (ret != HAL_OK) {
...fail
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think when the return value is needed only to be tested straight, it's not really needed to be stored then tested, as here. Is this function, below, the return value is used not only with an if()
instruction.
That said, I'm fine using the latter way (among the 2 you mentioned above).
drivers/eeprom/eeprom_stm32.c
Outdated
if (ret != HAL_OK) { | ||
LOG_ERR("failed to write to EEPROM (err %d)", ret); | ||
HAL_FLASHEx_DATAEEPROM_Lock(); | ||
k_mutex_unlock(&lock); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seomthing's wrong in the 1st commit. EEPROM should be locked back. I'll fix.
drivers/eeprom/eeprom_stm32.c
Outdated
if (HAL_FLASHEx_DATAEEPROM_Unlock() != HAL_OK) { | ||
return -EIO; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think when the return value is needed only to be tested straight, it's not really needed to be stored then tested, as here. Is this function, below, the return value is used not only with an if()
instruction.
That said, I'm fine using the latter way (among the 2 you mentioned above).
bfde38d
to
bc8ef62
Compare
drivers/eeprom/eeprom_stm32.c
Outdated
ret = HAL_FLASHEx_DATAEEPROM_Lock(); | ||
if (ret != HAL_OK) { | ||
LOG_ERR("failed to lock to EEPROM (err %d)", ret); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HAL_FLASHEx_DATAEEPROM_Lock
only implemented on L0/L1 and does not perform error checking.
I'm fine to perform the error checking, but LOG_ERR with value report seems overkill.
Correct eeprom_stm32_write() to return a valid errno instead of mixing HAL return values and errno return values. Clarify HAL return value is of type HAL_StatusTypeDef and not an int in eeprom_stm32_read(). Remove printing of HAL_FLASHEx_DATAEEPROM_Lock() error code since not very useful. Signed-off-by: Etienne Carriere <[email protected]>
Add missing test of HAL_FLASHEx_DATAEEPROM_Unlock() return value. By the way, add a error trace message when failing to relock the EEPROM after we failed to program it. Signed-off-by: Etienne Carriere <[email protected]>
bc8ef62
to
430dc60
Compare
Review comment addressed. |
HAL_FLASHEx_DATAEEPROM_Unlock(); | ||
hal_ret = HAL_FLASHEx_DATAEEPROM_Unlock(); | ||
if (hal_ret != HAL_OK) { | ||
LOG_ERR("failed to unlock to EEPROM"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOG_ERR still feels overkill but ok
|
Correct
eeprom_stm32_write()
to return a valid errno instead of mixing HAL return values and errno return values.Clarify HAL return value is of type
HAL_StatusTypeDef
and not anint
ineeprom_stm32_read()
.